#coding=utf-8
import unittest
from selenium import webdriver
from appium import webdriver
from time import sleep
from nav_plugin_op import nav_plugin_factory
from selenium.common.exceptions import WebDriverException
import os
from Public import BasePage
from Tool.usefulTools import userfulToolsFactory
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from Public import BaseConstant

#实例化基础数据

navOpenFactory = nav_plugin_factory()
userfulTool = userfulToolsFactory()
element_oprate_instance = element_Oprate()
basicAction = BasicAction()
Coordinatequery_Paramter_instances = BaseConstant.Coordinatequery_Paramter
# nav_name = "工作"
# plugin_name = "坐标查询"
nav_name = ["导航栏工作",'xpath',"//android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.widget.RadioButton"]
plugin_name = ["插件列表-坐标查询",'name','坐标查询']

class coordinate_query_factory():

	def open_coordinatequery_plug(self,driver,file_path):

		try:
			element_oprate_instance.element_click(nav_name,file_path)
			driver.swipe(400,1000,400,50,1200)
            # 点击"坐标查询"的插件，打开插件
			element_oprate_instance.element_click(plugin_name,file_path)
            #等待坐标查询页面内容进行加载，加载完成之后进行页面确认并界面

			if element_oprate_instance.element_display_commit(Coordinatequery_Paramter_instances.query_btn_name, file_path):
				element_oprate_instance.element_save_pic(file_path, 'open_coordinatequery_plug_successful')
			else:
				print 'test failed'

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'open_coordinatequery_plug_fail')
			raise

	def coordinate_query(self,driver,file_path):
		#查询
		try:
			#选择查询日期
			#driver.find_element_by_id(query_StartDate_id).click()
			#选择开始时间
			#driver.find_element_by_id(query_StartTime_id).click()
			#选择结束时间
			#driver.find_element_by_id(query_EndTime_id).click()
			#点击查询
			element_oprate_instance.element_click(Coordinatequery_Paramter_instances.query_btn_id, file_path)
			sleep(5)
			if element_oprate_instance.element_display_commit(Coordinatequery_Paramter_instances.track_playback_name, file_path):
				element_oprate_instance.element_save_pic(file_path, 'coordinate_query_successful')
			else:
				print 'test failed'
			element_oprate_instance.element_click(Coordinatequery_Paramter_instances.track_playback_name, file_path)
			element_oprate_instance.element_click(Coordinatequery_Paramter_instances.exit_id, file_path)

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'coordinate_query_fail')
			raise	

if __name__ == '__main__':
	unittest.main()

